{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2.2 矩阵乘法"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "两个矩阵相乘得到第三个矩阵：\n",
    "\n",
    "$$\n",
    "\\bf C=AB\n",
    "$$\n",
    "\n",
    "为了使得定义合法，我们需要 $\\mathbf A$ 的形状为 $m\\times n$, $\\mathbf B$ 的形状为 $n\\times p$，得到的矩阵为 $\\mathbf C$ 的形状为 ${m\\times p}$。\n",
    "\n",
    "定义为\n",
    "\n",
    "$$\n",
    "C_{i,j} = \\sum_{k} A_{i,k}B_{k,j}\n",
    "$$\n",
    "\n",
    "注意矩阵乘法不是逐元素相乘，逐元素相乘又叫 `Hadamard` 乘积，记作 $\\bf A\\odot B$。\n",
    "\n",
    "向量可以看出是列为 $1$ 的矩阵，两个相同大小的向量 $\\bf x, y$ 的点乘（`dot product`）或者内积，可以使用矩阵乘法表示为 $\\bf x^\\top y$。\n",
    "\n",
    "我们也可以把矩阵乘法理解为： $C_{i,j}$ 表示 $\\bf A$ 的第 $i$ 行与 $\\bf B$ 的第 $j$ 列的点乘。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 矩阵乘法的性质"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "矩阵乘法满足结合律（`associative`）和分配律（`distributive`）：\n",
    "\n",
    "$$\n",
    "\\begin{align}\n",
    "\\bf A(B+C)&=\\bf AB+AC \\\\\n",
    "\\bf A(BC)&=\\bf (AB)C\n",
    "\\end{align}\n",
    "$$\n",
    "\n",
    "矩阵乘法通常是不可交换的：\n",
    "\n",
    "$$\n",
    "\\bf AB \\neq BA\n",
    "$$\n",
    "\n",
    "但是向量内积是可交换的：\n",
    "\n",
    "$$\n",
    "\\bf x^\\top y = y^\\top x\n",
    "$$\n",
    "\n",
    "矩阵乘法的转置形式如下：\n",
    "\n",
    "$$\n",
    "\\bf (AB)^\\top = B^\\top A^\\top\n",
    "$$\n",
    "\n",
    "利用这个式子和标量转置等于其本身，我们马上得到内积是可交换的结论：\n",
    "\n",
    "$$\n",
    "\\bf x^\\top y = (x^\\top y)^\\top = y^\\top x\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 线性方程组"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "线性方程组可以表示为矩阵和向量乘法的形式：\n",
    "\n",
    "$$\n",
    "\\bf Ax = b\n",
    "$$\n",
    "\n",
    "其中 $\\mathbf A\\in\\mathbb R^{m\\times n}, \\mathbf b\\in\\mathbb R^{m}$ 是已知的，$\\mathbf x\\in\\mathbb R^{n}$ 是我们要求的未知量。\n",
    "\n",
    "它是线性方程组的一种紧凑表示：\n",
    "\n",
    "$$\n",
    "\\begin{align}\n",
    "\\mathbf A_{1,:} \\mathbf x&=b_1 \\\\\n",
    "\\mathbf A_{2,:} \\mathbf x&=b_2 \\\\\n",
    "\\dots &\\\\\n",
    "\\mathbf A_{m,:} \\mathbf x&=b_m \\\\\n",
    "\\end{align}\n",
    "$$"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
